package test01

class Point1(val x: Int, val y: Int)


trait Rectangular1 {

  def topLeft: Point1

  def bottomRight: Point1

  def left = topLeft.x

  def right = bottomRight.x

  def width = right - left
}

// topLeft 重构了 def topLeft: Point
// left、right、width 有初始化值
class Rectangle1 extends Rectangular1 {
  var topLeft: Point1= _
  var bottomRight: Point1= _
}

object Rectangle1 {

  def main(args: Array[String]): Unit = {

    val rect = new Rectangle1

    rect.topLeft = new Point1(1, 1)
    rect.bottomRight =new Point1(10, 10)

    println("rect.left==>" + rect.left)
    println("rect.right==>" + rect.right)
    println("rect.width==>" + rect.width)

  }

}